﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using CommonTools;
using MotionIoLib;
using log4net;
using BaseDll;
using System.Drawing;
using StationDemo.设备信息.helper;

//运动 安全检测函数，安全返回true  不安全返回false
//public delegate bool IsSafeWhenAxisMoveHandler(int nAxisNo);
//public event IsSafeWhenAxisMoveHandler m_eventIsSafeWhenAxisMove = null;

//Io操作 安全检测函数，安全返回true  不安全返回false
///public delegate bool IsSafeWhenOutIoHandler(string ioName, bool bVal);
//public event IsSafeWhenOutIoHandler m_eventIsSafeWhenOutIo;
//public delegate void ChangeMotionIoOrPosHandler(int nAxisNo, bool[] bChangeBitArr, AxisIOState state, AxisPos axisPos);
//public event ChangeMotionIoOrPosHandler m_eventChangeMotionIoOrPos;
//public delegate bool IsSafeWhenAxisMoveHandler(int nAxisNo, double currentpos, double dsstpos, MoveType moveType);
//public event IsSafeWhenAxisMoveHandler m_eventIsSafeWhenAxisMove = null;

namespace StationDemo
{
    public static class Safe
    {
        public static bool IsSafeWhenTableAxisMoveHandler(int nAxisNo, double currentpos, double dsstpos, MoveType moveType)
        {
            if (GlobalVariable.g_StationState == StationState.StationStateEmg)
            {
                AlarmMgr.GetIntance().WarnWithDlg((int)AlarmList.安全定义, new string[] { "确认" }, new string[] { $"设备处于未回零状态，请先回零" });
                return false;
            }

            if (nAxisNo == StationHelper.Station_Table.AxisU)
            {
                if (moveType == MoveType.JOG_N || moveType == MoveType.JOG_P)
                {
                    AlarmMgr.GetIntance().WarnWithDlg((int)AlarmList.安全定义, new string[] { "确认" }, new string[] { $"转盘禁止 手动Jog运动，请选择其他" });
                    return false;
                }
            }
            return true;
        }
        public static void AddAllSafeCheck()
        {
            if (!MotionMgr.GetInstace().IsSafeFunRegister(IsSafeWhenTableAxisMoveHandler))
                MotionMgr.GetInstace().m_eventIsSafeWhenAxisMove += IsSafeWhenTableAxisMoveHandler;
        }

        public static void DelectAllSafeCheck()
        {
            MotionMgr.GetInstace().m_eventIsSafeWhenAxisMove -= IsSafeWhenTableAxisMoveHandler;

        }


    }
}
